package codetop.huawei.T554;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: 18362
 * @Create: 2022-09-11 21:44:15 星期日
 */
class Solution {
    public int leastBricks(List<List<Integer>> wall) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int i=0; i<wall.size(); ++i) {
            int sum = 0;
            for (int j = 0; j < wall.get(i).size()-1; j++) {
                sum += wall.get(i).get(j);
                map.put(sum, map.getOrDefault(sum, 0) + 1);
            }
        }
        int maxCnt = 0;
        for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
            maxCnt = Math.max(maxCnt, entry.getValue());
        }
        return wall.size() - maxCnt;
    }
}